package model;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class HomeObject {

	private SessionFactory sess_fact;
	private Transaction t;
	private Session s;
			
	public HomeObject(){
		ConnectionSingleton c = ConnectionSingleton.getInstance();
		sess_fact = c.getSess_fact();
		s= sess_fact.getCurrentSession();
		t = s.getTransaction();
	}
	
	protected SessionFactory getSessionFactory() {
		return sess_fact;
	}
	
	public List findAll(Class clazz) {
        List objects = null;
        try {
            Query query = s.createQuery("from " + clazz.getName());
            objects = query.list();
        } catch (HibernateException e) {
            e.printStackTrace();
        }
        return objects;
    }
	
	public Session getSession() {
		return s;	
	}
	
}
